// 引组长（小公司称呼：老大）的包
import request from '@/utils/request';

// 拉取所有的一级分类
export function getCategoryLevel1() {
  return request({
    url: '/category-level1',
    method: 'get',
    params: null
  });
};

// 删除一级分类
export function delLevel1(id) {
  return request({
    url: '/category-level1/' + id,
    method: 'delete',
    params: null
  });
};

// 增加一级分类
export function addLevel1({ text }) {
  return request({
    url: '/category-level1',
    method: 'post',
    data: {
      text
    }
  });
};

// 修改一级分类名称
export function modifyLevel1Name({ id, text }) {
  return request({
    url: '/category-level1/' + id,
    method: 'patch',
    data: {
      text
    }
  });
};

// 修改一级分类排序
export function sortLevel1({ level1id, oldindex, newindex }) {
  return request({
    url: '/category-level1',
    method: 'patch',
    data: {
      level1id, oldindex, newindex
    }
  });
};

// 拉取指定一级分类下面的二三级分类
export function getLevel23(parentid) {
  return request({
    url: '/category-level23',
    method: 'get',
    params: {
      parentid
    }
  });
};

// 修改二级分类排序
export function sortLevel2({ level1id, level2id, oldindex, newindex }) {
  return request({
    url: '/category-level2',
    method: 'patch',
    // data就是HTTP请求体中的内容
    data: {
      level1id, level2id, oldindex, newindex
    }
  });
};

// 修改三级分类排序
export function sortLevel3({ level1id, level3id, fromlevel2id, oldindex, tolevel2id, newindex }) {
  return request({
    url: '/category-level3/',
    method: 'patch',
    data: {
      level1id, level3id, fromlevel2id, oldindex, tolevel2id, newindex
    }
  });
};

// 删除二级分类
export function delLevel2({ parentid, level2id }) {
  return request({
    url: '/category-level2/' + level2id,
    method: 'delete',
    params: {
      parentid
    }
  });
};

// 增加二级分类
export function addLevel2({ parentid, text }) {
  return request({
    url: '/category-level2',
    method: 'post',
    params: {
      parentid
    },
    data: {
      text
    }
  });
};

// 修改二级分类
export function modifyLevel2({ parentid, level2id, text }) {
  return request({
    url: '/category-level2/' + level2id,
    method: 'patch',
    params: {
      parentid
    },
    data: {
      text
    }
  });
};

// 删除三级分类
export function delLevel3({ level1id, level2id, level3id }) {
  return request({
    url: '/category-level3/' + level3id,
    method: 'delete',
    params: {
      level1id, level2id
    }
  });
};


// 增加三级分类
export function addLevel3({ level1id, level2id, text }) {
  return request({
    url: '/category-level3',
    method: 'post',
    params: {
      level1id, level2id
    },
    data: {
      text
    }
  });
};


// 修改三级分类名称
export function modifyLevel3({ level1id, level2id, level3id, text }) {
  return request({
    url: '/category-level3/' + level3id,
    method: 'patch',
    params: {
      level1id, level2id
    },
    data: {
      text
    }
  });
};